<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      width: 400px;
      height: 50px;
      background-color: #e1e7d3;
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div id="app">
    <input type="text" v-model="msg">
    {{msg}}
    <hr>
    <button @click="arr.push(arr.length+1)">新增数组</button>
    {{arr}}
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const  app = createApp({
      data(){
        return {
          msg: 'hello',
          arr: [1,2,3,4]
        }
      },
      // 侦听器立即触发 添加  immediate: true
      watch: {
        msg: {
          handler(newVal, oldVal){
            console.log('msg改变新值', newVal, '旧值', oldVal);
          },
          immediate: true
        },
        arr: {
          handler(newVal){
            console.log('arr改变', newVal);
          },
          deep: true,
          immediate: true
        }
      }
    })

    app.mount('#app')
  </script>
</body>
</html>